package main

import (
	"encoding/json"
	"fmt"
)

type Movie struct {
	// Title  string   `json:"title"`
	// Year   int      `json:"year"`
	// Price  int      `json:"price"`
	// Actors []string `json:"actors"`

	Title  string
	Year   int
	Price  int
	Actors []string
}

func goJson() {
	movie := Movie{
		Title:  "Comedy",
		Year:   2019,
		Price:  100,
		Actors: []string{"Tom", "Jerry"},
	}
	// 编码
	data, err := json.Marshal(movie)
	if err != nil {
		fmt.Println("json marshal failed, err:", err)
		return
	}
	fmt.Printf("json:%s\n", data)
	// 解码
	var m Movie
	err = json.Unmarshal(data, &m)
	if err != nil {
		fmt.Println("json unmarshal failed, err:", err)
		return
	}
}
